# -*- coding: utf-8 *-*
from src.helper.movement import MovementHelper
from src.handler.event import EventHandler
from src.event.entity import EntityClickEvent
from src.event.block import BlockClickEvent

class MouseHelper:

    @staticmethod
    def raytraceClick(world, x, y, dx, dy):
        x = x / 64.0 + dx
        y = y / 64.0 + dy
        block = world.getBlockAt(x, y)
        for entity in world.entities:
            if MovementHelper.isPointInRect((x, y), (entity.x, entity.y, entity.width, entity.height)):
                EventHandler.post(EntityClickEvent(entity))
                if entity.onClick(x, y):
                    return True
        if block is not None:
            EventHandler.post(BlockClickEvent(block))
            block.onClick(world, x, y)
